package Servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

import DAL.Entites.UsedGame;
import DAL.JDBC.DBConn;
import DAL.JDBC.UsedGameJDBC;

public class GetUsedGames extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public GetUsedGames() {
        super();
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		JSONObject result = new JSONObject();
		UsedGameJDBC gameJDBC = new UsedGameJDBC(DBConn.getConnection());
		
		List<UsedGame>	games = gameJDBC.listUsedGames();
		
		try {
			result.put("games", games);
		} 
		catch (JSONException e) {
			e.printStackTrace();
		}
		
		PrintWriter pw = response.getWriter();
		pw.write(result.toString());
	}

}
